<template>
  <div class="home">
    <div class="swiper-container">
      <div class="swiper-wrapper">
          <div
            class="swiper-slide"
            v-for="banner in banners"
            :key="banner.id"

          >
            <img :src="banner.imageUrl" alt="">
          </div>
      </div>
      <!-- 如果需要分页器 -->
      <div class="swiper-pagination"></div>

      <!-- 如果需要导航按钮 -->
      <div class="swiper-button-prev"></div>
      <div class="swiper-button-next"></div>
    </div>
    <div>
      vant组件使用
      <van-button type="danger">这是一个vant按钮</van-button>
    </div>
  </div>
</template>

<script>
import { getBanners } from '@/api/home'
import Swiper from 'swiper'
import 'swiper/swiper.scss'
// import Vue from 'vue'
// import { Button } from 'vant'

// Vue.use(Button)

export default {
  name: 'Home',
  data () {
    return {
      banners: []
    }
  },
  created () {
  //  发起ajax请求
    getBanners()
      .then(res => {
        console.log(res)
        this.banners = res
        this.$nextTick(() => {
          /* eslint-disable-next-line */
          new Swiper('.swiper-container', {
            autoplay: true,
            loop: true, // 循环模式选项
            // 如果需要分页器
            pagination: {
              el: '.swiper-pagination'
            },

            // 如果需要前进后退按钮
            navigation: {
              nextEl: '.swiper-button-next',
              prevEl: '.swiper-button-prev'
            },

            // 如果需要滚动条
            scrollbar: {
              el: '.swiper-scrollbar'
            }
          })
        })
      })
  },
  mounted () {
    /* eslint-disable-next-line */
    // new Swiper('.swiper-container', {
    //   loop: true, // 循环模式选项
    //   // 如果需要分页器
    //   pagination: {
    //     el: '.swiper-pagination'
    //   },

    //   // 如果需要前进后退按钮
    //   navigation: {
    //     nextEl: '.swiper-button-next',
    //     prevEl: '.swiper-button-prev'
    //   },

    //   // 如果需要滚动条
    //   scrollbar: {
    //     el: '.swiper-scrollbar'
    //   }
    // })
  }
}
</script>

<style lang="scss" scoped>
.swiper-container {
    width: 100%;
    height: 0px;
    padding-top:calc(100% * 378/1008);
    position: relative;
    .swiper-wrapper {
      position: absolute;
      left:0;
      top:0;
      img{
        width: 100%;
        height: 100%;
      }
    }
}
</style>
